//
//  CachingProvider.m
//  iPhoneMyRailApp
//
//  Created by Dinah Challen on 29/10/2008.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "CachedURLContents.h"


@implementation CachedURLContents

@synthesize lastUpdate, cachedURL, cachedValue;


- (BOOL) isInCache:(NSString*)url;{
	//NSLog(@"Cached time %f",[[NSDate date] timeIntervalSinceDate:lastUpdate] );
	return ([[NSDate date] timeIntervalSinceDate:lastUpdate] <= CACHE_EXPIRE_TIME) && ([self.cachedURL isEqual:url]);
}

- (id) cacheURL:(NSString*)url value:(id)v; {
	// Don't cache a nil value
	if (v != nil) {
		//[cachedValue release];
		self.cachedURL = url;
		self.cachedValue = v;
		self.lastUpdate = [NSDate date];
	}
	return v;
}


- (void)dealloc {
	[lastUpdate release];
	[cachedValue release];
    [super dealloc];
}

@end
